{layout name="public/layout" /}
{include file='yxnavbar'}
<style type="text/css">

    .exclusive-image  li{
        list-style: none;
        display: inline-block;
        height: 300px;/*当图片尺寸不一的时候，设置一个高度*/
        width: 18%;/*三列图片排列*/
        /*三列图片排列*/
        text-align: center;
        /*内容居中*/
        overflow: hidden;
        /*超出隐藏*/
        vertical-align: bottom;
        /*内容底部对齐*/
    }

     .content {
        width:90%;
        padding: 5px 0;
        overflow: hidden;
    }

     .img-wrap {
        padding: 10px;
        background-color: #fff;
        border: 1px solid #ccc;
    }

     .img-box {
        height: 215px;
        overflow: hidden;
    }
     .img-box img {
        position: relative;
        width: 100%;
        top: 50%;
        transform: translateY(-50%);
    }
     .title{
        padding-top: 8px;
        font-size: 12px;
        color: #454545;
        height: 25px;
        overflow: hidden;
    }
     .title2{
        font-size: 15px;
        color: #db0c0c;
    }
</style>




<div class="main">
    <ul class="nav nav-tabs">
        <li><a href="{php echo createWebUrl('exclusive_image',array('op'=>'display','themeid'=>$themeid));}">列表</a></li>
        <li class="active"><a href="{php echo createWebUrl('exclusive_image',array('op'=>'add','themeid' => $themeid));}">上传</a></li>
    </ul>
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">基本信息</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="themeid" value="{$themeid}"/>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">专版图片</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('img_url');}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style='color:red'>*</span>专版名称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control" placeholder="" name="title" value="">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">秀场公司</label>
                    <div class="col-sm-9 col-xs-12">
                        <select id="company" name="company">
                            <option value="0">请选择秀场公司</option>
                            {loop $companylists $row}
                            <option value="{$row['id']}">{$row['name']}</option>
                            {/loop}
                        </select>
                        <span class="help-block"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">销售人员</label>
                    <div class="col-sm-9 col-xs-12">
                        <select  name="salesman">
                            <option value="0">请选择所属销售</option>
                            {loop $wlist $row}
                              <option value="{$row['uid']}"> {$row['username']}</option>
                            {/loop}
                        </select>
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">设计师</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="designer" >
                            <option value="0">请选择设计师</option>
                            {loop $wlist $row}
                            <option value="{$row['uid']}"> {$row['username']}</option>
                            {/loop}
                        </select>
                        <span class="help-block"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">相似专版</label>
                    <div class="col-sm-9 col-xs-12 exclusive-image" >
                        <ul id="exclusive_image">

                        </ul>
                    </div>
                </div>

                <div class="form-group" id="sub_upload" style="text-align: center">
                    <div class="col-sm-12" >
                        <input name="submit" onclick="addItem()" id="btnCheck" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    var affirm_post = 0;
    var realtime_search_res = '';
    var old_img_url = '';
    //新增\修改奖品 提交数据
    function addItem() {
        let postUrl = "{php echo createWebUrl('exclusive_image',array('op'=>'save','themeid'=>$themeid));}";
        let success_redirect = "{php echo createWebUrl('exclusive_image',array('op'=>'display','themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:$.param({affirm_post:affirm_post,realtime_search_res:realtime_search_res,old_img_url:old_img_url})+'&'+jQuery('#form2').serialize(),
            success:function (e) {
                let res = e.result;
                let status = e.status;
                let msg = res.msg;
                if (status!=1){
                    if(status==2){    //有相似度图片
                        var html = "";
                        res.data.forEach(function(d){
                            html +=
                                "<li>\n" +
                                "    <div class=\"content\">\n" +
                                "       <div class=\"img-wrap\">\n" +
                                "        <div class=\"img-box\">\n" +
                                "          <img src="+d.img_url+">\n" +
                                "               </div>\n" +
                                "            </div>\n" +
                                "          <div\n" +
                                "                 class=\"title\">"+d.title+"\n" +
                                "             </div>\n" +
                                "            <div class=\"title\">相似度：<span class=\"title2\">"+d.score+"</span></div>\n" +
                                "        </div>\n" +
                                " </li>"
                        });
                        $("#exclusive_image").append(html);
                        realtime_search_res = res.realtime_search_res;
                        affirm_post = 1;
                        old_img_url = res.old_img_url;
                    }
                    layer.msg(msg)

                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>